<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Example 8.3: Bounding correlation coefficients</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch08_geometric_probs/html/ex_8_3.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Example 8.3: Bounding correlation coefficients</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 10/09/05</span>
<span class="comment">%</span>
<span class="comment">% Let C be a correlation matrix. Given lower and upper bounds on</span>
<span class="comment">% some of the angles (or correlation coeff.), find the maximum and minimum</span>
<span class="comment">% possible values of rho_14 by solving 2 SDP's</span>
<span class="comment">%           minimize/maximize   rho_14</span>
<span class="comment">%                        s.t.   C &gt;=0</span>
<span class="comment">%                               0.6 &lt;= rho_12 &lt;=  0.9</span>
<span class="comment">%                               0.8 &lt;= rho_13 &lt;=  0.9</span>
<span class="comment">%                               0.5 &lt;= rho_24 &lt;=  0.7</span>
<span class="comment">%                              -0.8 &lt;= rho_34 &lt;= -0.4</span>

n = 4;

<span class="comment">% Upper bound SDP</span>
fprintf(1,<span class="string">'Solving the upper bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C1(n,n)</span> <span class="string">symmetric</span>
    maximize ( C1(1,4) )
    C1 &gt;= 0;
    diag(C1) == ones(n,1);
    C1(1,2) &gt;= 0.6;
    C1(1,2) &lt;= 0.9;
    C1(1,3) &gt;= 0.8;
    C1(1,3) &lt;= 0.9;
    C1(2,4) &gt;= 0.5;
    C1(2,4) &lt;= 0.7;
    C1(3,4) &gt;= -0.8;
    C1(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);

<span class="comment">% Lower bound SDP</span>
fprintf(1,<span class="string">'Solving the lower bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C2(n,n)</span> <span class="string">symmetric</span>
    minimize ( C2(1,4) )
    C2 &gt;= 0;
    diag(C2) == ones(n,1);
    C2(1,2) &gt;= 0.6;
    C2(1,2) &lt;= 0.9;
    C2(1,3) &gt;= 0.8;
    C2(1,3) &lt;= 0.9;
    C2(2,4) &gt;= 0.5;
    C2(2,4) &lt;= 0.7;
    C2(3,4) &gt;= -0.8;
    C2(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);
<span class="comment">% Displaying results</span>
disp(<span class="string">'--------------------------------------------------------------------------------'</span>);
disp([<span class="string">'The minimum and maximum values of rho_14 are: '</span> num2str(C2(1,4)) <span class="string">' and '</span> num2str(C1(1,4))]);
disp(<span class="string">'with corresponding correlation matrices: '</span>);
disp(C2)
disp(C1)
</pre>
<a id="output"></a>
<pre class="codeoutput">
Solving the upper bound SDP ... 
Calling sedumi: 18 variables, 12 equality constraints
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 12, order n = 13, dim = 25, blocks = 2
nnz(A) = 20 + 0, nnz(ADA) = 144, nnz(L) = 78
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            1.49E+00 0.000
  1 :  -2.96E-01 4.40E-01 0.000 0.2954 0.9000 0.9000   1.63  1  1  1.2E+00
  2 :  -4.38E-01 1.20E-01 0.000 0.2726 0.9000 0.9000   1.48  1  1  3.0E-01
  3 :  -2.52E-01 9.66E-03 0.000 0.0806 0.9900 0.9900   1.55  1  1  2.4E-02
  4 :  -2.31E-01 5.64E-04 0.355 0.0584 0.9900 0.9900   1.08  1  1  1.4E-03
  5 :  -2.30E-01 2.30E-05 0.000 0.0408 0.9900 0.9900   1.00  1  1  5.7E-05
  6 :  -2.30E-01 1.31E-07 0.325 0.0057 0.9853 0.9990   1.00  1  1  5.0E-07
  7 :  -2.30E-01 8.10E-09 0.000 0.0617 0.9900 0.9629   1.00  1  1  3.1E-08
  8 :  -2.30E-01 2.90E-10 0.389 0.0358 0.9900 0.9900   1.00  2  2  1.1E-09

iter seconds digits       c*x               b*y
  8      0.0   Inf -2.2990908487e-01 -2.2990908453e-01
|Ax-b| =   1.7e-09, [Ay-c]_+ =   2.4E-10, |x|=  2.8e+00, |y|=  2.3e+00

Detailed timing (sec)
   Pre          IPM          Post
1.000E-02    3.000E-02    0.000E+00    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1159.48.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.229909
Done! 
Solving the lower bound SDP ... 
Calling sedumi: 18 variables, 12 equality constraints
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 12, order n = 13, dim = 25, blocks = 2
nnz(A) = 20 + 0, nnz(ADA) = 144, nnz(L) = 78
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            1.49E+00 0.000
  1 :  -3.13E-01 4.52E-01 0.000 0.3033 0.9000 0.9000   1.63  1  1  1.2E+00
  2 :  -5.41E-01 1.28E-01 0.000 0.2843 0.9000 0.9000   1.52  1  1  3.1E-01
  3 :  -4.09E-01 1.21E-02 0.000 0.0943 0.9900 0.9900   1.62  1  1  2.3E-02
  4 :  -3.93E-01 2.43E-04 0.000 0.0201 0.9900 0.9900   1.11  1  1  4.4E-04
  5 :  -3.93E-01 1.26E-05 0.145 0.0520 0.9900 0.9900   1.00  1  1  2.3E-05
  6 :  -3.93E-01 1.76E-07 0.000 0.0139 0.9574 0.9900   1.00  1  1  5.8E-07
  7 :  -3.93E-01 6.56E-09 0.030 0.0373 0.9900 0.9900   1.00  1  1  2.2E-08
  8 :  -3.93E-01 1.29E-09 0.061 0.1973 0.9000 0.9000   1.00  2  2  4.3E-09

iter seconds digits       c*x               b*y
  8      0.0   Inf -3.9282032728e-01 -3.9282032607e-01
|Ax-b| =   6.6e-09, [Ay-c]_+ =   9.6E-10, |x|=  2.8e+00, |y|=  1.8e+00

Detailed timing (sec)
   Pre          IPM          Post
0.000E+00    3.000E-02    1.000E-02    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 2421.04.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -0.39282
Done! 
--------------------------------------------------------------------------------
The minimum and maximum values of rho_14 are: -0.39282 and 0.22991
with corresponding correlation matrices: 
    1.0000    0.6000    0.8486   -0.3928
    0.6000    1.0000    0.2940    0.5000
    0.8486    0.2940    1.0000   -0.5807
   -0.3928    0.5000   -0.5807    1.0000

    1.0000    0.7291    0.8000    0.2299
    0.7291    1.0000    0.3202    0.5943
    0.8000    0.3202    1.0000   -0.4000
    0.2299    0.5943   -0.4000    1.0000

</pre>
</div>
</body>
</html>